﻿using System;
using System.Windows.Input;

namespace Socium.Presentation {
	/// <summary>
	/// This ViewModelBase subclass requests to be removed 
	/// from the UI when its CloseCommand executes.
	/// This class is abstract.
	/// </summary>
	public abstract class PageViewModel : NamedViewModel {
		#region Fields

		readonly ICommand _close_command;

		#endregion // Fields

		#region Constructor

		protected PageViewModel(string display_name, ICommand close_command) {
			DisplayName = display_name;
			_close_command = close_command;
		}

		protected PageViewModel(string display_name) {
			DisplayName = display_name;
			_close_command = new Command(OnRequestClose);
		}

		#endregion // Constructor

		#region CloseCommand

		/// <summary>
		/// Returns the command that, when invoked, attempts
		/// to remove this workspace from the user interface.
		/// </summary>
		public ICommand CloseCommand {
			get {
				return _close_command;
			}
		}

		#endregion // CloseCommand

		#region RequestClose [event]

		/// <summary>
		/// Raised when this workspace should be removed from the UI.
		/// </summary>
		public event EventHandler RequestClose;

		void OnRequestClose() {
			var handler = RequestClose;
			if (handler != null) {
				handler(this, EventArgs.Empty);
			}
		}

		#endregion // RequestClose [event]
	}
}